// vue.config.js
// const AntDesignThemePlugin = require("antd-theme-webpack-plugin");
const CompressionWebpackPlugin = require("compression-webpack-plugin")
const path = require("path")
const systemConfig = require("./src/config/config.js")


function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  outputDir: "build", // 打包目录
  publicPath: process.env.NODE_ENV === "production" ? "./" : "./", // 静态资源前缀，静态资源引入路径
  indexPath: "index.html", // index.html打包目录，此时根目录基于outputDir
  assetsDir: "./",
  productionSourceMap: false,
  // 生成的 HTML 中的 <link rel="stylesheet"> 和 <script> 标签上启用 Subresource Integrity (SRI)
  integrity: false,
  // webpack相关配置
  css: {
    // 是否分离css（插件ExtractTextPlugin）
    // extract: true,
    // 是否开启 CSS source maps
    sourceMap: false,
    loaderOptions: {
      less: {
        modifyVars: {
        },
        javascriptEnabled: true,
      },

    },
  },

  chainWebpack: (config) => {
    // 常用alias
    config.resolve.alias
      .set("@", resolve("src"))
      .set("@assets", resolve("src/assets"))
    // config
    //   .plugin('webpack-bundle-analyzer')
    //   .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
    config.performance
      .set("hints", false)

    // 移除 preload 插件
    config.plugins.delete("preload")
    // 移除 prefetch 插件
    config.plugins.delete("prefetch")
  },

  configureWebpack: (config) => {
		// 开发环境不需要gzip
		if (process.env.NODE_ENV !== "production") return
		config.plugins.push(
			new CompressionWebpackPlugin({
				// 正在匹配需要压缩的文件后缀
				test: /\.(js|css|svg|woff|ttf|json|html|less)$/,
				// 大于10kb的会压缩
				threshold: 10240,
			})
		)
	},
  pluginOptions:
    {
      "style-resources-loader": {
        preProcessor: "less",
        patterns: [
          resolve("./src/styles/common/common.less")
        ]
      }
    }
  ,
  devServer: {
    overlay: {
      warnings: true,
      errors: true,
    },
    proxy: { // 配置多个跨域
      "/apiDev": {
        target: systemConfig.environment.domain,
        changeOrigin: true,
        // ws: true,//websocket支持
        secure: false,
        pathRewrite: {
          "^/apiDev": "/api/v1",
        },
      },
      "/apiImg": {
        target: systemConfig.environment.domain,
        changeOrigin: true,
        // ws: true,//websocket支持
        secure: false,
        pathRewrite: {
          "^/apiImg": "/",
        },
      },

    },
  },
  // lintOnSave: "warning",
}
